package com.hyt.it.ogt.controller.ykcj.exam;

import com.hyt.it.ogt.controller.base.BaseController;
import com.hyt.it.ogt.ykcj.common.annotation.Log;
import com.hyt.it.ogt.ykcj.common.core.domain.AjaxResult;
import com.hyt.it.ogt.ykcj.common.core.page.TableDataInfo;
import com.hyt.it.ogt.ykcj.common.enums.BusinessType;
import com.hyt.it.ogt.ykcj.common.utils.DateUtils;
import com.hyt.it.ogt.ykcj.common.utils.SecurityUtils;
import com.hyt.it.ogt.ykcj.common.utils.poi.ExcelUtil;
import com.hyt.it.ogt.ykcj.domain.exam.ExamSubjectNameConfig;
import com.hyt.it.ogt.ykcj.service.exam.IExamSubjectNameConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiSort;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 考试科目名称配置Controller
 * 
 * @author admin
 * @date 2021-06-18
 */
@Api(tags = "exam.8.考试科目名称配置", value = "考试科目名称配置请求接口")
@ApiSort(value = 108)
@RestController
@RequestMapping("/exam/subjectConfig")
public class ExamSubjectNameConfigController extends BaseController
{
    @Autowired
    private IExamSubjectNameConfigService examSubjectNameConfigService;

    /**
     * 查询考试科目信息列表
     */
    @ApiOperation("查询考试科目信息列表")
    @GetMapping("/list")
    public TableDataInfo list(ExamSubjectNameConfig examSubjectNameConfig)
    {
        startPage();
        List<ExamSubjectNameConfig> list = examSubjectNameConfigService.selectExamSubjectNameConfigList(examSubjectNameConfig);
        return getDataTable(list);
    }

    /**
     * 导出考试科目信息列表
     */
    @ApiOperation("导出考试科目信息列表")
    @Log(title = "考试科目信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ExamSubjectNameConfig examSubjectNameConfig)
    {
        List<ExamSubjectNameConfig> list = examSubjectNameConfigService.selectExamSubjectNameConfigList(examSubjectNameConfig);
        ExcelUtil<ExamSubjectNameConfig> util = new ExcelUtil<ExamSubjectNameConfig>(ExamSubjectNameConfig.class);
        return util.exportExcel(list, "考试科目信息数据");
    }

    /**
     * 获取考试科目信息详细信息
     */
    @ApiOperation("获取考试科目信息详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(examSubjectNameConfigService.selectExamSubjectNameConfigById(id));
    }

    /**
     * 新增考试科目信息
     */
    @ApiOperation("新增考试科目信息")
    @Log(title = "考试科目信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamSubjectNameConfig examSubjectNameConfig)
    {
    	if(StringUtils.isEmpty(examSubjectNameConfig.getName())){
   		 return AjaxResult.error("请填写科目名称");
	   	}
	   	if(StringUtils.isEmpty(examSubjectNameConfig.getExamNameId())){
	   		return AjaxResult.error("请选择所属考试");
	   	}
	   	examSubjectNameConfig.setCreateBy(SecurityUtils.getUsername());
	   	examSubjectNameConfig.setCreateTime(DateUtils.getNowDate());
	   	examSubjectNameConfig.setUpdateBy(SecurityUtils.getUsername());
	   	examSubjectNameConfig.setUpdateTime(DateUtils.getNowDate());
	   	examSubjectNameConfig.setOfficeId(getOfficeId());
        examSubjectNameConfig.setDeptId(getDeptId());
        return toAjax(examSubjectNameConfigService.insertExamSubjectNameConfig(examSubjectNameConfig));
    }

    /**
     * 修改考试科目信息
     */
    @ApiOperation("修改考试科目信息")
    @Log(title = "考试科目信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamSubjectNameConfig examSubjectNameConfig)
    {
    	if(StringUtils.isEmpty(examSubjectNameConfig.getId())){
     		 return AjaxResult.error("科目信息Id未获取到");
  	   	}
    	if(StringUtils.isEmpty(examSubjectNameConfig.getName())){
      		 return AjaxResult.error("请填写科目名称");
   	   	}
   	   	if(StringUtils.isEmpty(examSubjectNameConfig.getExamNameId())){
   	   		return AjaxResult.error("请选择所属考试");
   	   	}
   	   	examSubjectNameConfig.setUpdateBy(SecurityUtils.getUsername());
   	   	examSubjectNameConfig.setUpdateTime(DateUtils.getNowDate());
        return toAjax(examSubjectNameConfigService.updateExamSubjectNameConfig(examSubjectNameConfig));
    }

    /**
     * 删除考试科目信息
     */
    @ApiOperation("删除考试科目信息")
    @Log(title = "考试科目信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
    	if(ids== null || ids.length == 0){
    		 return AjaxResult.error("参数不能为空");
 	   	}
        return toAjax(examSubjectNameConfigService.deleteExamSubjectNameConfigByIds(ids));
    }
}
